package com.zsy.controller;

import com.zsy.annoation.ReportLogAnno;
import com.zsy.pojo.PageResult;
import com.zsy.pojo.Result;
import com.zsy.pojo.Student;
import com.zsy.pojo.StudentQueryParam;
import com.zsy.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-06 21:02
 **/
@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 分页查询 + 条件查询学生
     * @param studentQueryParam
     * @return
     */
    @GetMapping
    public Result queryStudent(StudentQueryParam studentQueryParam){
        PageResult<Student> pageResult = studentService.queryStudent(studentQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryStudentById(@PathVariable Integer id){
        Student student = studentService.queryStudentById(id);
        return Result.success(student);
    }

    /**
     * 增加学生
     * @param student
     * @return
     */
    @PostMapping
    @ReportLogAnno
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }

    /**
     * 修改学生
     * @param student
     * @return
     */
    @PutMapping
    @ReportLogAnno
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

    /**
     * 批量删除学生
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ReportLogAnno
    public Result deleteByIds(@PathVariable List<Integer>ids){
        log.info("批量删除学生:{}",ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 学生违纪扣分
     * @param id
     * @param score
     * @return
     */
    @PutMapping("/violation/{id}/{score}")
    @ReportLogAnno
    public Result updateViolationStu(@PathVariable Integer id,  @PathVariable Short score){
        studentService.updateViolationStu(id,score);
        return Result.success();
    }


}
